var data1 = [];
$(function() {
    $.ajax({
        type : "get",
        url : "/admin/labor/hutrainnotice/selectTree",
        success : function(data, status) {
                data1 = eval("[" + data + "]");
        },
        error : function() {
            toastr.error('Error');
        },
    });
    $("#txt_departmentname").click(function() {
         var options = {
             bootstrap2 : false,
             showTags : false,
             levels : 5,
             showCheckbox : true,
             checkedIcon : "glyphicon glyphicon-check",
             data : buildDomTree(),
             onNodeSelected : function(event, data) {
                 $("#txt_departmentname").val(data.text);
                 $("#visbleRange").val(data.id);
                 $("#treeview").hide();
             }
         };
         $('#treeview').treeview(options);
    });
});

function buildDomTree() {
    var data = [];
    var root = "所有分类";
    function walk(nodes, data) {
        if (!nodes) {
            return;
        }
        console.log(nodes);
        $.each(nodes, function(id, node) {
            var obj = {
                id : node.id,
                text : node.text != null ? node.text : root
                //                                      tags : [ node.isLeaf == true ? node.
                //                                              + ' child elements'
                //                                              : '' ]
            };
            if (node.isLeaf = true) {
                obj.nodes = [];
                walk(node.children, obj.nodes);
            }
            data.push(obj);
        });
    }
    walk(data1, data);
    return data;
}

function selectOption(id,url){
    $.ajax({
        type:"get",
        url:url,
        success:function (data) {
            var option='';
            for(var i=0;i<data.length;i++){
                option+='<option value="'+data[i].id+'">'
                    +data[i].cateName
                    +'</option>';
            }
            $("#"+id).html(option);
        },
        error : function() {
            toastr.error('Error');
        },
    })
}

/************二维数组联动下拉框***********/

var employType=['转移就业','自主创业','特设公益性岗位','公益专岗','公益性岗位'];

var childrenType=[['省内','省外','市内','乡镇'],['省内','省外','市内','乡镇'],['医院','政府','公园','马路'],['广场','博物馆','文化馆'],['一环','二环','三环','四环']];

